brute force math *1000

Please click on ads to support us..

Python Code:

import itertools
import heapq
import collections
import math
import sys


input = sys.stdin.readline


def inp():
    return (int(input()))


def inlt():
    return (list(map(int, input().split())))


def insr():
    s = input()
    return (list(s[:len(s) - 1]))


def invr():
    return (map(int, input().split()))


def inis():
    return (input().split())


def stlt():
    return list(map(str, input().split()))






            
def SieveOfEratosthenes(n):
    prime = [True for i in range(n+1)]
    p = 2
    l = []
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    for p in range(2, n+1):
        if prime[p]:
            l.append(p)
                    else:
            continue
    return l


def isPrime(n):
    prime_flag = 0

    if n > 1:
        for i in range(2, int(math.sqrt(n)) + 1):
            if n % i == 0:
                prime_flag = 1
                break
        if prime_flag == 0:
            return True
        else:
            return False
    else:
        return False


def gcdofarray(a):
    x = 0
    for p in a:
        x = math.gcd(x, p)
    return x


def printDivisors(n):
        i = 1
    ans = []
    while i <= math.sqrt(n):

        if (n % i == 0):

                        if (n / i == i):
                ans.append(i)
            else:
                                ans.append(i)
                ans.append(n // i)
        i = i + 1
    ans.sort()
    return ans


def CountDivisors(n):
        i = 1
    ans = []
    while i <= math.sqrt(n):

        if (n % i == 0):

                        if (n / i == i):
                ans.append(i)
            else:
                                ans.append(i)
                ans.append(n // i)
        i = i + 1
    ans.sort()
    return len(ans)


def binaryToDecimal(n):
    return int(n, 2)


def countTriplets(a, n):
    s = set()
    for i in range(n):
        s.add(a[i])
    count = 0
    for i in range(n):
        for j in range(i + 1, n, 1):
            xr = a[i] ^ a[j]
            if xr in s and xr != a[i] and xr != a[j]:
                count += 1
    return int(count // 3)


def generate_twin_prime(n):
    a = 0
    for i in range(1, n + 1):
        j = i + 2
        if isPrime(i) and isPrime(j):
            if 2 ^ (i ^ j) == 0:
                a += 1
    return a


def smallestDivisor(n):
    if (n % 2 == 0):
        return 2
    i = 3
    while (i * i <= n):
        if (n % i == 0):
            return i
        i += 2
    return n


def countOdd(L, R):
    N = (R - L) // 2

        if (R % 2 != 0 or L % 2 != 0):
        N += 1

    return N


def isPalindrome(s):
    return s == s[::-1]


def sufsum(test_list):
    test_list.reverse()
    res = [sum(test_list[: i + 1]) for i in range(len(test_list))]
    return res


def prsum(lst):
    return (list(itertools.accumulate(lst)))


def badachotabadachota(nums):
    nums.sort()
    i = 0
    j = len(nums) - 1
    ans = []
    cc = 0
    while len(ans) != len(nums):
        if cc % 2 == 0:
            ans.append(nums[j])
            j -= 1
        else:
            ans.append(nums[i])
            i += 1
        cc += 1
    return ans


def primeFactors(n):
    ans = []
    while n % 2 == 0:
        ans.append(2)
        n = n // 2

    for i in range(3, int(math.sqrt(n))+1, 2):
        while n % i == 0:
            ans.append(i)
            n = n / i

            if n > 2:
        ans.append(n)
    return ans


def closestMultiple(n, x):
    if x > n:
        return x
    z = (int)(x / 2)
    n = n + z
    n = n - (n % x)
    return n


def can_form_palindrome(arr, n):
    MAX = 256
    s = ""
    for i in range(n):
        s = s + str(arr[i])
    freq = [0]*MAX
    for i in range(n):
        freq[arr[i]] = freq[arr[i]]+1
    count = 0
    for i in range(MAX):
        if (freq[i] & 1):
            count = count+1
        if (count > 1):
            return False
    return True


def getPairsCount(arr, n, sum):

    m = [0] * 1000
    for i in range(0, n):
        m[arr[i]] += 1
    twice_count = 0
    for i in range(0, n):
        twice_count += m[int(sum - arr[i])]
        if (int(sum - arr[i]) == arr[i]):
            twice_count -= 1
    return int(twice_count / 2)


def remove_consec_duplicates(test_list):
    res = [i[0] for i in itertools.groupby(test_list)]
    return res


def BigPower(a, b, mod):
    if b == 0:
        return 1
    ans = BigPower(a, b//2, mod)
    ans *= ans
    ans %= mod
    if b % 2:
        ans *= a
    return ans % mod


alphabets = list("abcdefghijklmnopqrstuvwxyz")

def check(r,g,b,w):
    return False if r%2 + g%2 + b%2 + w%2 > 1 else True

if __name__ == '__main__':
    T = int(input())
    for ttt in range(T):
        r,g,b,w = map(int,input().split())
        if check(r,g,b,w):
            print("Yes")
        elif r>0 and g>0 and b>0 and check(r-1,g-1,b-1,w+1):
            print("Yes")
        else :
            print("No")     

C++ Code:

#include <bits/stdc++.h>

#define S 400000
#define sc second
#define fr first
#define pb push_back
#define pf push_front
#define frn front
#define bc back
#define en endl
#define sst stringstream
#define sz(x) (x).size()
#define rev(x) reverse((x).begin(),(x).end())

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

using namespace std;

const int inf=2147483647;
const int ninf=-inf;
const int z4=1e4+5;
const int z5=1e5+5;
const int z6=1e6+5;
const int mod=1000000007;

string al="abcdefghijklmnopqrstuvwxyz";
string AL="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

bool con(int a,int b,int c,int d){
    int cnt=0;
    if(a&1) cnt++;
    if(b&1) cnt++;
    if(c&1) cnt++;
    if(d&1) cnt++;
    if(cnt==0||cnt==1){
        return true;
    }
    else if(cnt==3||cnt==4){
        if(min(a,min(b,c))>=1) return true;
    }
    return false;
}

signed main () {
    ios_base::sync_with_stdio (false);
    cin.tie (0);
    cout.tie (0);
    // freopen("sum.in","r",stdin);
    // freopen("sum.out","w",stdout);
    
    int q;
    cin>>q;
    while(q--){
        int r,g,b,w;
        cin>>r>>g>>b>>w;
        bool f=con(r,g,b,w);
        cout<<(f?"Yes":"No")<<en;
    }
    
  return 0;
}


Comments

Submit
0 Comments
More Questions

841. Keys and Rooms
152. Maximum Product Subarray
337. House Robber III
869. Reordered Power of 2
1593C - Save More Mice
1217. Minimum Cost to Move Chips to The Same Position
347. Top K Frequent Elements
1503. Last Moment Before All Ants Fall Out of a Plank
430. Flatten a Multilevel Doubly Linked List
1290. Convert Binary Number in a Linked List to Integer
1525. Number of Good Ways to Split a String
72. Edit Distance
563. Binary Tree Tilt
1306. Jump Game III
236. Lowest Common Ancestor of a Binary Tree
790. Domino and Tromino Tiling
878. Nth Magical Number
2099. Find Subsequence of Length K With the Largest Sum
1608A - Find Array
416. Partition Equal Subset Sum
1446. Consecutive Characters
1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram
938. Range Sum of BST
147. Insertion Sort List
310. Minimum Height Trees
2110. Number of Smooth Descent Periods of a Stock
2109. Adding Spaces to a String
2108. Find First Palindromic String in the Array
394. Decode String